package com.yc.forum.servlet;

import com.yc.forum.dao.RedisDao;
import com.yc.forum.dao.UserDao;
import com.yc.forum.util.Utils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map;

//获得当前登录账号的个人信息
@WebServlet(name="GetUserMessagesByAccount",value = "/GetUserMessagesByAccount.s")
public class GetUserMessagesByAccount extends HttpServlet {
    UserDao userDao=new UserDao();
    RedisDao redisDao=new RedisDao();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取当前登录账号
        HttpSession session= req.getSession();
        String account=session.getAttribute("loginedUser").toString();
        if(account==null){
            resp.sendRedirect("login.html");
        }
        //从mysql获取数据
        Map<String,Object> userMessages=userDao.queryUserMessagesByAccount(account);
        //从redis获取数据
        int reward=redisDao.getreward(account);
        System.out.println("reward="+reward);
        userMessages.put("reward",reward);
        Utils.toJson(userMessages,resp);
    }

}
